//
//  WAMallCenterController.m
//  WalkiOS
//
//  Created by luqiuan on 2019/10/24.
//  Copyright © 2019 Chenmuzhou. All rights reserved.
//

#import "WAMallCenterController.h"
#import "WAMallCenterlistController.h"
@interface WAMallCenterController ()

@property (weak, nonatomic) IBOutlet UIView *bottomLineLB;
@property (weak, nonatomic) IBOutlet UIButton *noPayBtn;//待付款
@property (weak, nonatomic) IBOutlet UIButton *noSendBtn;//待发货
@property (weak, nonatomic) IBOutlet UIButton *noReceivedBtn;//待收货
@property (weak, nonatomic) IBOutlet UIButton *completedBtn;//已完成

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomLineLeftCons;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *scrollViewWidthCons;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;


@property (strong, nonatomic) WAMallCenterlistController *buyListVC;
@property (strong, nonatomic) WAMallCenterlistController *sellListVC;
@property (strong, nonatomic) WAMallCenterlistController *completingListVC;
@property (strong, nonatomic) WAMallCenterlistController *completedListVC;
@end

@implementation WAMallCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.scrollViewWidthCons.constant = WNScreenWidth * 3;
    
    self.buyListVC = [[WAMallCenterlistController alloc] initWithType:0];
    [self.scrollView addSubview:self.buyListVC.view];
    [self addChildViewController:self.buyListVC];
    [self.buyListVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.equalTo(self.scrollView);
        make.width.mas_equalTo(WNScreenWidth);
    }];
    
    self.completedListVC = [[WAMallCenterlistController alloc] initWithType:2];
    [self.scrollView addSubview:self.completedListVC.view];
    [self addChildViewController:self.completedListVC];
    [self.completedListVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.equalTo(self.scrollView);
        make.width.mas_equalTo(WNScreenWidth);
    }];
    
    self.sellListVC = [[WAMallCenterlistController alloc] initWithType:1];
    [self.scrollView addSubview:self.sellListVC.view];
    [self addChildViewController:self.sellListVC];
    [self.sellListVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self.scrollView);
        make.left.equalTo(self.buyListVC.view.mas_right);
        make.width.mas_equalTo(WNScreenWidth);
    }];
    
    
//    self.completingListVC = [WAMallCenterlistController new];
//    [self.scrollView addSubview:self.completingListVC.view];
//    [self addChildViewController:self.completingListVC];
//    [self.completingListVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.bottom.equalTo(self.scrollView);
//        make.left.equalTo(self.sellListVC.view.mas_right);
//        make.width.mas_equalTo(WNScreenWidth);
//    }];
}

- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)noPayBtnAction:(id)sender {
    if (self.noPayBtn.selected) {
        return;
    }
    self.noPayBtn.selected = YES;
    self.noSendBtn.selected = NO;
//    self.noReceivedBtn.selected = NO;
    self.completedBtn.selected = NO;
    [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES];
}

- (IBAction)noSendBtnAction:(id)sender {
    if (self.noSendBtn.selected) {
        return;
    }
    self.noPayBtn.selected = NO;
    self.noSendBtn.selected = YES;
//    self.noReceivedBtn.selected = NO;
    self.completedBtn.selected = NO;
    [self.scrollView setContentOffset:CGPointMake(WNScreenWidth, 0) animated:YES];
}

//- (IBAction)noReceivedBtnAction:(id)sender {
//    if (self.noReceivedBtn.selected) {
//        return;
//    }
//    self.noPayBtn.selected = NO;
//    self.noSendBtn.selected = NO;
//    self.noReceivedBtn.selected = YES;
//    self.completedBtn.selected = NO;
//    [self.scrollView setContentOffset:CGPointMake(WNScreenWidth, 0) animated:YES];
//}

- (IBAction)completedBtnAction:(id)sender {
    if (self.completedBtn.selected) {
        return;
    }
    self.noPayBtn.selected = NO;
    self.noSendBtn.selected = NO;
//    self.noReceivedBtn.selected = NO;
    self.completedBtn.selected = YES;
    [self.scrollView setContentOffset:CGPointMake(WNScreenWidth * 2, 0) animated:YES];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    CGFloat offset_X = scrollView.contentOffset.x;
    self.bottomLineLeftCons.constant = offset_X/3.f;
    [self.view layoutIfNeeded];
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    self.noPayBtn.selected = NO;
    self.noSendBtn.selected = NO;
//    self.noReceivedBtn.selected = NO;
    self.completedBtn.selected = NO;
    if (scrollView.contentOffset.x == 0) {
        self.noPayBtn.selected = YES;
    }else if (scrollView.contentOffset.x == WNScreenWidth * 1) {
        self.noSendBtn.selected = YES;
//    }else if (scrollView.contentOffset.x == WNScreenWidth * 2) {
//        self.noReceivedBtn.selected = YES;
    }else{
        self.completedBtn.selected = YES;
    }
}
@end
